function [R12, R22, Rf, Cf, Raf, Rbf, error]=obtainRauch (stage, stageType)

C=[0.47e-6, 1e-9, 1e-12, 1e-6, 1.2e-9, 1.2e-12, 1.5e-9, 1.5e-12, 1.8e-9, 1.8e-12, 10e-9, 10e-12, 10e-6, 100e-9, 100e-12, 100e-6, 1000e-12, 1000e-6, 12e-9, 12e-12, 120e-9, 120e-12, 15e-9, 150e-9, 150e-12, 18e-9, 18e-12, 180e-9, 180e-12, 2.2e-9, 2.2e-12, 2.2e-6, 2.7e-9, 2.7e-12, 22e-9, 22e-12, 22e-6, 220e-9, 220e-12, 220e-6, 2200e-6, 27e-9, 27e-12, 270e-9, 270e-12, 3.3e-9, 3.3e-12, 3.3e-6, 3.9e-9, 3.9e-12, 33e-9, 33e-12, 33e-6, 330e-9, 330e-12, 330e-6, 3300e-6, 39e-9, 39e-12, 390e-9, 390e-12, 4.7e-9, 4.7e-12, 4.7e-6, 47e-9, 47e-12, 47e-6, 470e-9, 470e-12, 470e-6, 4700e-6, 5.6e-9, 5.6e-12, 56e-9, 56e-12, 560e-9, 560e-12, 6.8e-9, 6.8e-12, 680e-9, 680e-12, 8.2e-9, 8.2e-12, 82e-9, 82e-12, 820e-12];
i=1;
error=1;
w0=abs(stage.stagePoles(1));
Q=abs(stage.stagePoles(1)/(2*real(stage.stagePoles(1))));
Q0=Q/3.5;
K1=(1-Q0/Q)/(2*Q0^2);           % K-1 es K1

for t=1:length(C)
    R=2*Q0/(w0*C(t));
    if R>10 && R<100000
        ZC=1/(C(t)*w0);
        if R<10*ZC && R>ZC/10
            Cf(i)=C(t);
            Rf(i)=R;
            i=i+1;
        end
    end
end
     
    R1=Rf/(4*Q0^2);
    m=stage.stageGain*stage.KtoAdd/(w0*2*Q0*(K1+1));
    R12=R1/m;
    R22=R1/(1-m);

i=1;
for Ra=logspace(2,4,50)
    Rb=K1*Ra; 
    Raf(i)=Ra;
    Rbf(i)=Rb;
    i=i+1;
end
for i=1:length(2*Rf)   % Ponele
    p=random('unid',length(Rf));
    if R12(p)>10 && R12(p)<300000 && R22(p)>10 && R22(p)<300000
        Rf=Rf(p);
        Cf=Cf(p);
        R12=R12(p);
        R22=R22(p);
        error=0;
        break;
    end
end
for i=1:length(2*Raf)   % Ponele
    p=random('unid',length(Raf));
    if Raf(p)>10 && Raf(p)<300000 && Rbf(p)>10 && Rbf(p)<300000
        Raf=Raf(p);
        Rbf=Rbf(p);
        break;
    else error=1;
    end
end
if error=1
    Rf=0;
    Cf=0;
    R12=0;
    R22=0; 
    Raf=0;
    Rbf=0;
end
if stageType==4 && error==0
   aux=Cf;
   R22=Cf*(1-m);
   R12=Cf*m;
   Cf=Rf;
   Rf=aux/(4*Q0^2);
end
end

